﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace laohan.Common.reporter
{
    /// <summary>
    /// 报表列
    /// </summary>
    public class ReporterColumnAttr
    {
        /// <summary>
        /// 报表编码
        /// </summary>
        public ReporterCode ReporterCode { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 列属性
        /// </summary>
        public List<ColumnAttr> Columns { get; set; }

        /// <summary>
        /// 报表列
        /// </summary>
        public static List<ReporterColumnAttr> ReporterColumnAttrs { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reporterCode"></param>
        /// <param name="name"></param>
        /// <param name="list"></param>
        public static void ReporterColumnAttrsAdd(ReporterCode reporterCode, string name, List<ColumnAttr> list)
        {
            ReporterColumnAttrs.Add(new ReporterColumnAttr()
            {
                ReporterCode = reporterCode,
                Name = name,
                Columns = list
            });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reporterCode"></param>
        /// <returns></returns>
        public static List<ColumnAttr> ReporterColumnAttrGetList(ReporterCode reporterCode)
        {
            var items = ReporterColumnAttrs.Where(w => w.ReporterCode == reporterCode).ToList();

            if (items.Count <= 0)
            {
                throw new Exception("没有任何报表，请联系管理员！");
            }

            if (items.Count > 1)
            {
                throw new Exception("对应的报表过多，请联系管理员！");
            }

            return items[0].Columns;
        }

        /// <summary>
        /// 设置信息
        /// </summary>
        public static void Setting()
        {
            ReporterColumnAttrs = new List<ReporterColumnAttr>();

            ReporterColumnAttrsAdd(ReporterCode.log_listLoginLog, "登入日志", log_listLoginLog_Columns());
            ReporterColumnAttrsAdd(ReporterCode.jxc_itemList, "进销存基础项目列表", jxc_itemList_Columns());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private static List<ColumnAttr> jxc_itemList_Columns()
        {
            var items = new List<ColumnAttr>();

            items.Add(new ColumnAttr("id", "编号", 65));
            items.Add(new ColumnAttr("code", "编码", 65));
            items.Add(new ColumnAttr("name", "名称", 120));
            items.Add(new ColumnAttr("jpm", "简拼码", 65));
            items.Add(new ColumnAttr("isCheckLibIn", "入库前是否检验(0:否 1：是)", 120, false));
            items.Add(new ColumnAttr("isWeighAutoPut", "过磅自动抛转检验申请单", 150, false));
            items.Add(new ColumnAttr("minSecurityStock", "库存(低)", 65));
            items.Add(new ColumnAttr("maxSecurityStock", "库存(高)", 65));
            items.Add(new ColumnAttr("details", "备注", 65, false));
            items.Add(new ColumnAttr("spec", "规格", 65));
            items.Add(new ColumnAttr("unit", "单位", 65));
            items.Add(new ColumnAttr("price", "价格", 65));
            items.Add(new ColumnAttr("createUserName", "创建人", 85));
            items.Add(new ColumnAttr("createTime", "创建时间", 120));

            return items;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="reporterCode"></param>
        /// <returns></returns>
        private static List<ColumnAttr> log_listLoginLog_Columns()
        {
            var items = new List<ColumnAttr>();

            items.Add(new ColumnAttr("id", "编号", 65));
            items.Add(new ColumnAttr("logId", "编号", false));
            items.Add(new ColumnAttr("userId", "用户编号", false));
            items.Add(new ColumnAttr("userName", "用户名称", 85));
            items.Add(new ColumnAttr("ipAddr", "IP地址", 100));
            items.Add(new ColumnAttr("callCount", "调用次数", 65));
            items.Add(new ColumnAttr("status", "状态", 45));
            items.Add(new ColumnAttr("msg", "提示信息", 100));
            items.Add(new ColumnAttr("timeStamp", "创建时间", 125));

            return items;
        }
    }
}